package com.wangzifan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangzifan.entity.Course;
import com.wangzifan.entity.PageBean;
import com.wangzifan.entity.Teacher;
import com.wangzifan.mapper.CourseMapper;
import com.wangzifan.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Course> courses = courseMapper.queryCourse();
        Page<Course> p = (Page<Course>) courses;

        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public Course queryCourseById(Integer id) {
        return courseMapper.queryCourseById(id);
    }

    @Override
    public void deleteCourse(List<Integer> ids) {
        courseMapper.deleteCourse(ids);
    }

    @Override
    public void addCourse(Course course) {
        courseMapper.addCourse(course);
    }

    @Override
    public void updateCourse(Course course) {
        courseMapper.updateCourse(course);
    }
}
